Don't always print an error on test failures
authorAlex Crichton <alex@alexcrichton.com>
Mon, 11 Aug 2014 04:48:43 +0000 (21:48 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 11 Aug 2014 04:49:46 +0000 (21:49 -0700)
Only print a failure if the command didn't have an exit status. Also, clarify
the failure message in the case that an exit was detected but it was not a
successful status.

Closes #350

src/bin/cargo-test.rs
src/cargo/util/process_builder.rs
tests/test_cargo_compile.rs
tests/test_cargo_test.rs

index cd1ce0e970bd6858ec05ccfc73293ca33c426391..873c20eb09845c38ea262a38101afc16b2f46c79 100644 (file)
@@ -56,11 +56,10 @@ fn execute(options: Options, shell: &mut MultiShell) -> CliResult<Option<()>> {
     match err {
         None => Ok(None),
         Some(err) => {
-            let status = match err.exit {
-                Some(ExitStatus(i)) => i as uint,
-                _ => 101,
-            };
-            Err(CliError::from_boxed(err.mark_human(), status))
+            Err(match err.exit {
+                Some(ExitStatus(i)) => CliError::new("", i as uint),
+                _ => CliError::from_boxed(err.mark_human(), 101)
+            })
         }
     }
 }
index a0322e380bd4b49e61cf5498eca5b17b391f5114..da88b33f439f6de8ff5cafe4ff76e9018d5487ea 100644 (file)
@@ -59,34 +59,36 @@ impl ProcessBuilder {
                .stderr(InheritFd(2))
                .stdin(InheritFd(0));
 
-        let msg = || format!("Could not execute process `{}`",
-                             self.debug_string());
-
-        let exit = try!(command.status().map_err(|e|
-            process_error(msg(), Some(e), None, None)));
+        let exit = try!(command.status().map_err(|e| {
+            process_error(format!("Could not execute process `{}`",
+                                  self.debug_string()),
+                          Some(e), None, None)
+        }));
 
         if exit.success() {
             Ok(())
         } else {
-            Err(process_error(msg(), None, Some(&exit), None))
+            Err(process_error(format!("Process didn't exit successfully: `{}`",
+                                      self.debug_string()),
+                              None, Some(&exit), None))
         }
     }
 
     pub fn exec_with_output(&self) -> Result<ProcessOutput, ProcessError> {
         let command = self.build_command();
 
-        let msg = || format!("Could not execute process `{}`",
-                             self.debug_string());
-
         let output = try!(command.output().map_err(|e| {
-            process_error(msg(), Some(e), None, None)
+            process_error(format!("Could not execute process `{}`",
+                                  self.debug_string()),
+                          Some(e), None, None)
         }));
 
         if output.status.success() {
             Ok(output)
         } else {
-            Err(process_error(msg(), None, Some(&output.status),
-                              Some(&output)))
+            Err(process_error(format!("Process didn't exit successfully: `{}`",
+                                      self.debug_string()),
+                              None, Some(&output.status), Some(&output)))
         }
     }
 
index aee2b4e602031a324218af3de6d29bc98055dfe0..d5d3f0555b9e6a1921e176795fcbb247f15bdd46 100644 (file)
@@ -671,7 +671,7 @@ test!(custom_build_failure {
         "#);
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(101).with_stderr(format!("\
-Could not execute process `{}` (status=101)\n\
+Process didn't exit successfully: `{}` (status=101)\n\
 --- stderr\n\
 task '<main>' failed at 'nope', {filename}:2\n\
 \n\
@@ -732,7 +732,7 @@ test!(custom_second_build_failure {
         "#);
     assert_that(p.cargo_process("cargo-build"),
                 execs().with_status(101).with_stderr(format!("\
-Could not execute process `{}` (status=101)\n\
+Process didn't exit successfully: `{}` (status=101)\n\
 --- stderr\n\
 task '<main>' failed at 'nope', {filename}:2\n\
 \n\
index 2fb1b97724888131fc31d5f4ee6fc1b4dfd20cb5..1d551c6bc6a045c7449f1a6724370c79cfa1488b 100644 (file)
@@ -147,8 +147,7 @@ test result: FAILED. 0 passed; 1 failed; 0 ignored; 0 measured
         sep = path::SEP))
               .with_stderr(format!("\
 task '<main>' failed at 'Some tests failed', [..]
-Could not execute process `{test}[..]` (status=101)
-", test = p.root().join("target/test/foo").display()))
+"))
               .with_status(101));
 })